package com.backend.modules.system.entity;

import com.backend.common.entity.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import lombok.ToString;

@Data
@Entity
@ToString(exclude = {"department","teacherClasses"})
@Table(name = "sys_user")
@EqualsAndHashCode(callSuper = true)
public class SysUser extends BaseEntity {

    @Column(nullable = false, unique = true, length = 64)
    private String username;

    @Column(nullable = false)
    private String password;

    @Column(nullable = false, unique = true, length = 32)
    private String userCode;

    @Column(nullable = false, length = 64)
    private String realName;

    @Column(length = 11)
    private String phone;

    @Column(length = 128)
    private String email;

    private String avatar;

    @Column(nullable = false)
    private Boolean status = true;

    @Column(nullable = false)
    private Integer userType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "department_id")
    private SysDepartment department;
    
    @Column(name = "department_id", insertable = false, updatable = false)
    private Long departmentId;

    @Column(length = 64)
    private String position; // 职位，仅教师有此字段

    @Schema(description = "性别(1:男,2:女)")
    @Column(name = "gender")
    private Integer gender;

    /**
     * 教师班级列表，关联 sys_teacher_class，一个教师有多个班级
     */
    @OneToMany(mappedBy = "teacher")
    private List<SysTeacherClass> teacherClasses = new ArrayList<>();
} 